package data.structure.lianbiao;


import com.alibaba.fastjson.JSON;

import java.util.Arrays;
import java.util.List;

/**
 * @ClassName: ListNode
 * @Description:
 * @Author: qiaopengxiang
 * @Date: 2022/6/30 17:52
 */
public class ListNode {

   public int data;
   public ListNode next;

    public static void main(String[] args) {
        ListNode listNode = new ListNode(0);
        List<Integer> integers = Arrays.asList(1, 2, 3, 4, 5, 6);
        integers.forEach(e->{
            listNode.add(e);
        });
        System.out.println(JSON.toJSONString(listNode));
        listNode.print();
        Integer integer = listNode.find(6);
        System.out.println(integer);

    }

    public ListNode(int data) {
        this.data = data;
    }

    public  void add(int data){
        ListNode listNode = new ListNode(data);
        if (this.next==null){
            this.next = listNode;
        }else {
            this.next.add(data);
        }
   }

   public void print(){
       System.out.println(this.data);
       if (this.next!=null){
           this.next.print();
       }
   }

   Integer a = null;
   public Integer find(int data){
        if (this.data ==data){
            return this.data;
        }
        ListNode node = this.next;
        while (node!=null){
            if (node.data ==data){
                return node.data;
            }
            node = node.next;
        }
        return null;

   }
}
